
package www.wmx.com.xssc.domain.vo.jcyjj;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@NoArgsConstructor
public class BaseSearchLW {

    @ApiModelProperty(value = "序号")
    Integer xh;
    @ApiModelProperty(value = "论文名称")
    String lwmc;
    @ApiModelProperty(value = "发表刊物")
    String fbkw;
    @ApiModelProperty(value = "影响因子")
    String yxyz;
    @ApiModelProperty(value = "发表时间")
    LocalDateTime fbsj;
    @ApiModelProperty(value = "国内作者")
    List<String> gnzz = new ArrayList<>();
    @ApiModelProperty(value = "作者排名")
    Integer zzpm;
    @ApiModelProperty(value = "SCI他引次数")
    Integer tycs;
    @ApiModelProperty(value = "他引总次数")
    Integer tyzcs;

    public BaseSearchLW(Integer xh, String lwmc, String fbkw, String yxyz, LocalDateTime fbsj, List<String> gnzz, Integer zzpm,
                        Integer tycs, Integer tyzcs) {
        this.xh = xh;
        this.lwmc = lwmc;
        this.fbkw = fbkw;
        this.yxyz = yxyz;
        this.fbsj = fbsj;
        this.gnzz = gnzz;
        this.zzpm = zzpm;
        this.tycs = tycs;
        this.tyzcs = tyzcs;
    }

    // 解析器类
    public static List<BaseSearchLW> parseLW(String data) {
        List<BaseSearchLW> article = new ArrayList<>();
        int indexXH = data.indexOf("1");
        if(indexXH==-1) return  null;
        data = data.substring(indexXH);
        String[] lines = data.split("\\r?\\n");
        for (int i = 0; i < lines.length; i += 10) {
            Integer xh = Integer.parseInt(lines[i].trim());
            String lwmc = lines[i+1].trim();
            String fbkw = lines[i+2].trim();
            String yxyz = lines[i+3].trim();
            LocalDateTime fbsj = LocalDate.parse(lines[i + 4].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay();
            List<String> gnzz = Arrays.asList(lines[i + 5].trim().split("、"));;
            Integer zzpm = Integer.parseInt(lines[i+6].trim());
            Integer tycs = lines[i+7]!=null && !lines[i+7].trim().isEmpty()  ? Integer.parseInt(lines[i+7].trim()) : null;
            Integer tyzcs = Integer.parseInt(lines[i+8].trim());
            article.add(new BaseSearchLW( xh,  lwmc,  fbkw,  yxyz,  fbsj,  gnzz, zzpm, tycs, tyzcs));
        }
        return article;
    }


}
